from orders.models import OrderInfo, OrderGoods
from rest_framework import serializers
from goods.models import SKU


class OrderSimpleSerializer(serializers.Serializer):
    order_id = serializers.CharField(read_only=True)
    create_time = serializers.DateTimeField(read_only=True)


class SKUSerializer(serializers.ModelSerializer):
    class Meta:
        model = SKU
        fields = ['name', 'default_image_url']


# class SKUSerializer(serializers.Serializer):
#     name = serializers.CharField(read_only=True)
#     default_image_url = serializers.CharField(read_only=True)


class OrderGoodsSerializer(serializers.ModelSerializer):
    sku = SKUSerializer(read_only=True)
    class Meta:
        model = OrderGoods
        fields = '__all__'


class OrderDetailSerializer(serializers.ModelSerializer):
    user = serializers.StringRelatedField(read_only=True)
    skus = OrderGoodsSerializer(read_only=True, many=True)

    class Meta:
        model = OrderInfo
        fields = '__all__'

